package com.wdh.kjs.Adapter;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wdh.kjs.R;
import com.wdh.kjs.activity.MessageDetailsActivity;
import com.wdh.kjs.activity.NoticeDetailsActivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by dingh on 2016/4/20.
 */

public class MessageListAdapter extends BaseAdapter {
    private List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
    private Context context;
    private HashMap<String, String> maps = new HashMap<String, String>();
    public MessageListAdapter(Context context, List<HashMap<String, String>> data) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;

        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = View.inflate(context, R.layout.item_station_message, null);
            viewHolder.tv_message_title = (TextView) convertView.findViewById(R.id.tv_message_title);
            viewHolder.tv_message_time = (TextView) convertView.findViewById(R.id.tv_message_time);
            viewHolder.icon_red = (ImageView) convertView.findViewById(R.id.icon_red);
            viewHolder.redPacket = (ImageView) convertView.findViewById(R.id.redPacket);
            viewHolder.stationMessage_LinearLayout = (LinearLayout) convertView.findViewById(R.id.stationMessage_LinearLayout);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        maps = data.get(position);
//        ItemClick itemClick = new ItemClick(position);
//        viewHolder.stationMessage_LinearLayout.setOnClickListener(itemClick);
        if (maps != null) {
            viewHolder.tv_message_title.setText(maps.get("tv_message_title"));
            viewHolder.tv_message_time.setText(maps.get("tv_message_time"));
        }
        if(maps.get("userMessageState").equals("1")){
            viewHolder.icon_red.setBackgroundResource(R.drawable.bt_gray_oval_solid);
        }
        return convertView;
    }

    class ViewHolder {
        TextView tv_message_title;
        TextView tv_message_time;
        ImageView icon_red;
        ImageView redPacket;
        LinearLayout stationMessage_LinearLayout;
    }

//    private class ItemClick implements View.OnClickListener{
//        private int Myposition;
//        public ItemClick(int position) {
//            Myposition = position;
//        }
//
//        @Override
//        public void onClick(View v) {
//            Intent intent = new Intent(context, MessageDetailsActivity.class);
//            intent.putExtra("userReceiveMessageId", data.get(Myposition).get("userReceiveMessageId"));
//            context.startActivity(intent);
//
//        }
//    }
}